package br.com.decsoft.lv.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ResourceBundle;

public class ConnectionFactory {
	
	public static Connection getConnection() throws SQLException {

        ResourceBundle jdbcProp;
        jdbcProp = ResourceBundle.getBundle("resources/jdbc");  

        final String driverName = jdbcProp.getString("driverName");
		final String serverName = jdbcProp.getString("serverName");
		final String myDatabase = jdbcProp.getString("myDatabase");
		final String sqlDialect = jdbcProp.getString("sqlDialect");
		final String url = "jdbc:firebirdsql:"  + serverName + ":" + myDatabase + "?sql_dialect=" + sqlDialect;
		final String username = jdbcProp.getString("username");
		final String password = jdbcProp.getString("password");

		try {
			Class.forName(driverName);
			return DriverManager.getConnection(url, username, password);
		} catch (ClassNotFoundException e) {
			throw new SQLException(e.getMessage());
		} catch (SQLException e) {
			throw new SQLException(e.getMessage());
		}
	}
}